package com.naizhuai.network;

import com.naizhuai.network.exception.ApiException;

import rx.Observer;

/**
 * @author：lichenxi
 * @date 2018/2/27 15
 * email：525603977@qq.com
 * Fighting
 */
public abstract class NetWorkObserver<T> implements Observer<T> {
    protected abstract void onFail(String errormsg);

    protected abstract void onSuccess(T result);

    @Override
    public final void onCompleted() {

    }

    @Override
    public final void onError(Throwable e) {
        try {
            ApiException.showExceptionDetails(e);
            onFail(ApiException.showExceptionDetails(e));
        } catch (ArrayIndexOutOfBoundsException e1) {
            onFail(e.getMessage());
        }

    }

    @Override
    public final void onNext(T result) {
        onSuccess(result);
    }
}
